<?php
class User
{
    public static function get($id)
    {
        return Db::get('_user')->select()->where(array('id'=>$id))->getOne();
    }

	public static function getName($id){
        return Db::get('User')->select('name')->where(array('id'=>$id))->getCol();
	}
	
	public static function getAll($where=array(), $s=0, $l=0, $order='id ASC'){
        return Db::get('_user')->select()->where($where)->order($order)->limit($s, $l)->hkey('id')->getAll();
	}

    public static function getList() {
		return self::getAll('id>1 AND id!='.UID.' AND is_disa=0');
    }
    public static function count($where=array())
    {
        return Db::get(__CLASS__)->count()->where($where)->getCol();
    }
	
	public static function getPureList($where=array(), $order='id ASC'){
        return Db::get('User')->select('name')->where('id>1 AND id!='.UID.' AND is_disa=0',$where)
				->order($order)->hkey('id')->getCols();
	}

    public static function add($data)
    {
        return Db::get(__CLASS__)->insert($data)->exec() ? Db::get(__CLASS__)->insertId() : false;
    }
    public static function update($id, $data)
    {
        return Db::get(__CLASS__)->update($data)->where(array('id'=>$id))->exec();
    }
	
	static function getByAccount($name)
	{
		if(!($name=trim($name))) {
			return false;
		}
		return Db::get(__CLASS__)->select()->where(array('account'=>$name))->getOne();
	}

	/**
	 * 取虚拟角色ID
	 */
	static function getVirtualRoleId($id)
	{
		return Db::get(__CLASS__)->select('role_id')->where(array('id'=>$id))->getCol();
	}
	
}
?>
